<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<script src="./vue2.js"></script>
<body>
    <div id="box">
        <input v-model="ulText" />
        <button @click="handelAdd()">Add</button>
        <ul v-show="list.length">
            <li v-for="(item,index) in list">
                {{item}}-----第{{index+1}}条
                <button @click="handelDel(index)">Del</button>
            </li>
        </ul>
        <div v-show="!list.length">待办事项空空如也</div>
    </div>
    <script>
        new Vue({
            el:'#box',
            data:{
                list:['aaa','bbb','ccc'],
                ulText:''
            },
            methods:{
                handelAdd(){
                    if(this.ulText){
                        this.list.push(this.ulText)
                        this.ulText=''
                    }else{
                        alert('不能输入空的待办事项')
                    }
                },
                handelDel(index){
                    this.list.splice(index,1)
                }
            }
        })
    </script>
</body>
</html>